﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using DevLib.SuperTool;

/** 
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
 * Description: 
 * Author: Heller (HellerSong@outlook.com)
 * CreationTime: 3/28/2015 3:41:20 PM
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
 **/
namespace DevGrammar.TestBasic
{
	[TestClass]
	public class TestBasic
	{
		[TestMethod]
		public void test_system_path_related()
		{
			Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
			Console.WriteLine(Path.DirectorySeparatorChar);
			Console.WriteLine(Environment.CurrentDirectory);
		}

		[TestMethod]
		public void test_show_special_chars_with_hexadecimal()
		{
			// Show invalid chars in file system
			int num = 0x22;
			Console.WriteLine((char)num);
			num = 60;
			Console.WriteLine((char)num);
			num = 0x3e;
			Console.WriteLine((char)num);
			num = 0x7c;
			Console.WriteLine((char)num);
			num = 0x20;
			Console.WriteLine((char)num);

			Console.WriteLine((int)'a');

			// byte of Enter
			Console.WriteLine((char)13);
		}

		[TestMethod]
		public void test_char_ascii()
		{
			Console.WriteLine((char)('A' + 3));
		}

		[TestMethod]
		public void test_file_or_directory_exists()
		{
			Console.WriteLine(Directory.Exists(@"D:\"));
			Console.WriteLine(Directory.Exists(@"D:\test.txt"));      // False
			Console.WriteLine(File.Exists(@"D:\test.txt"));             // True
		}

		[TestMethod]
		public void test_write_boolean_value()
		{
			Console.WriteLine(true);	// It a string "True", not the number "1"
		}

		[TestMethod]
		public void test_generate_guid()
		{
			Console.WriteLine("The new created GUID is: " + Guid.NewGuid());
		}

		[TestMethod]
		public void test_convert_string_to_int()
		{
			int i = Int32.Parse("309");
			Console.WriteLine(i);
		}

		[TestMethod]
		public void test_boxing_and_unboxing()
		{
			/*
			 * Boxing,		will convert value type to reference type
			 * Unboxing,	will convert reference type to value type 
			 */
			int myIntNumber = 20;
			object myObject = myIntNumber;          // Box the int to object
			int mySecondNumber = (int)myObject;   // Unbox it back into an int 
		}

		[TestMethod]
		public void test_ternary_operator()
		{
			Console.WriteLine(3 < 4 ? "Result is: true" : "Result is: false");
		}

		[TestMethod]
		public void test_compare_file_last_change_time()
		{
			// [Bug] I think there is a bug with git tracked file with last write time
			FileInfo f1 = new FileInfo(Path.Combine(DevGlobal.PATH_RESOURCE, "FileChangeTime1.txt"));
			FileInfo f2 = new FileInfo(Path.Combine(DevGlobal.PATH_RESOURCE, "FileChangeTime2.txt"));
			DateTime dt1 = f1.LastWriteTimeUtc;
			DateTime dt2 = f2.LastWriteTimeUtc;
			Console.WriteLine("File1 last write time: " + dt1.ToString());
			Console.WriteLine("File2 last write time: " + dt2.ToString());
			Console.WriteLine("dt1 different compare to dt2 result: " + dt1.CompareTo(dt2));
		}

		[TestMethod]
		public void test_try_catch_finally()
		{
			try
			{
				Console.WriteLine("Before Error Occure!");
				int i1 = Convert.ToInt32("abc");
				Console.WriteLine("After Error Occure!");   // It do not execute when error occure
			}
			catch (Exception e)
			{
				Console.WriteLine("If error this catch exception block will run. Error details: ");
				Console.WriteLine("\t" + e.Message);
				Console.WriteLine("\t" + e.StackTrace);
			}
			finally
			{
				Console.WriteLine("This finally block will run aynway!");
			}
			// Process will execute in order normally after try-catch
			Console.WriteLine("After Catch Exception!");	// There's no effect on code block that out of try-catch
		}




	}
}
